//
//$Id: generic.h 175 2009-09-12 17:34:23Z Oleg.Bulychov $
#pragma once
#ifndef GENERIC_H
#define GENERIC_H

#include "src/heo/include/lf_endl.h"
#include "src/heo/include/random.h"
#include "src/heo/include/reflection.h"
#include "src/heo/include/optimization_direction.h"

struct Generic_Config
{
    int         dummy_;

    template<class V>
    void accept(V& v)
    {
        v(VAR_(dummy),               0);
    }
};
//__________________________________________________________________________________
struct Generic_Problem
{
    int dummy_;

    explicit Generic_Problem():
        dummy_(0)
    {}

    template<class I>
    bool read(I& in)
    {
        in >> dummy_;
        return true;
    }
};
//__________________________________________________________________________________
//__________________________________________________________________________________
class Generic_Solution
{
    DISALLOW_COPY_AND_ASSIGN(Generic_Solution);
public:
    //typedef maximization<> TDirection;
    typedef minimization<> TDirection;
    typedef int            TCostType;
protected:
    TCostType    cost_;
    bool         changed_;
public:
    explicit Generic_Solution(): cost_(0), changed_(false)
    {}

    ~Generic_Solution()
    {
    }

    void init(Generic_Problem const& problem, Generic_Config const& cfg)
    {
    }

    void generate_Random(Generic_Config const& cfg, uniform_random& rnd)
    {
        changed_ = true;
    }

    void generate_Trivial()
    {
        changed_ = false;
        cost_ = 0;
    }

    int get_Cost() const
    {
        ASSERT_(!changed_);
        return cost_;
    }

    void evaluate(Generic_Problem const& problem)
    {
        if (!changed_)
            return;
        changed_ = false;
        cost_ = 0;
    }

    void assign(Generic_Solution const& sol)
    {
        changed_ = sol.changed_;
        cost_    = sol.cost_;
    }

    void print(std::ostream& os, Generic_Problem const& problem, Generic_Config const& cfg)
    {
        os << lf
            << "cost: " << get_Cost() << lf;
    }

    bool is_Solved(Generic_Problem const& problem) const
    {
        return false;//cost_ == problem.dimension_;
    }

    template<class V>
    void accept(V& v)
    {
        v(cost_);
        v(changed_);
    }
};
//__________________________________________________________________________________

#endif
//EOF!
